package ch.bfh.mobicomp;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class SodaRecoveryServiceActivity extends Activity implements
		OnClickListener {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		Button button1 = (Button) findViewById(R.id.button1);
		
		EditText editText = (EditText)findViewById(R.id.editTextDate);
		
		editText.setText("5");

		button1.setOnClickListener(this);

	}

	@Override
	public void onClick(View v) {
		if (v.getId() == R.id.button1) {

			EditText dateField = (EditText) findViewById(R.id.editTextDate);
			
			long starttimeInMs = 0;
			
			//Start Recovery in X sec
			starttimeInMs = System.currentTimeMillis() + Integer.parseInt(dateField.getText().toString()) * 1000;
		

			/*String format = "yyyy-MM-dd HH:mm";
			SimpleDateFormat sdf = new SimpleDateFormat(format);
			Date date;
			try {
				date = sdf.parse(dateField.getText().toString());
				starttimeInMs = date.getTime();
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}*/
			
			//Intent startIntent = new Intent("INTENT_ALARM_SET");
			//startIntent.putExtra("starttimeInMs", starttimeInMs);
			//sendBroadcast(startIntent);
			
			RecoveryAlarmManager ram = new RecoveryAlarmManager();
			ram.startRecovery(getApplicationContext(), starttimeInMs);
			
			
		}
	}
}